#include "UISessionModel.h"
#include <QDateTime>
#include <QDebug>
using namespace IM_GUI_KIT;

UISessionModel::UISessionModel(QObject *parent):QObject (parent)
{
  qDebug()<<"init UISessionModel";
}

UISessionModel::~UISessionModel()
{
  qDebug()<<"delete UISessionModel :"<<m_sessionId;
}

QString UISessionModel::getSession() const
{
  return m_sessionId;
}

void UISessionModel::setSession(const QString &sessionid)
{
  if(sessionid!=m_sessionId)
      m_sessionId=sessionid;
  emit sessionChanged();
}

UISessionModel::UISessionModel(const QString sessionid  , const QString &name, const QString &icon, const int64_t timestamp, const QString summary, int unRead, QObject *parent):QObject (parent)
{
  m_sessionId=sessionid;
  m_name=name;
  m_icon=icon;
//  m_timeNow=timestamp;
  m_timestamp=timestamp;
  m_timeNow=QDateTime::fromTime_t(timestamp/1000).toString("hh:mm:ss");
  m_summary=summary;
  m_unread=unRead;
}

QString UISessionModel::getName() const
{
    return m_name;
}

void UISessionModel::setName(const QString &name)
{
    if(name!=m_name)
        m_name=name;
    emit nameChanged();
}

QString UISessionModel::getIcon() const
{
    return m_icon;
}

void UISessionModel::setIcon(const QString &icon)
{

    if (m_icon!=icon)
        m_icon=icon;
    emit iconChanged();
}

QString UISessionModel::getTimeNow() const
{
    return m_timeNow;

}

void UISessionModel::setTimeNow(const QString &timeNow)
{

    if (m_timeNow!=timeNow)
        m_timeNow=timeNow;
    emit timeNowChanged();
}

QString UISessionModel::getSummary() const
{
    return m_summary;
}

void UISessionModel::setSummary(const QString &summary)
{
    if (m_summary!=summary)
        m_summary=summary;
    emit summaryChanged();
}

int UISessionModel::getUnread()
{
    return m_unread;
}

void UISessionModel::setUnread(const int &unread)
{
    if (m_unread!=unread)
        m_unread=unread;
    emit unreadChanged();
}

void UISessionModel::setTimeStamp(const int64_t time)
{
  if(time!=m_timestamp){
      m_timestamp=time;
      m_timeNow=QDateTime::fromTime_t(time/1000).toString("hh:mm:ss");
      emit timeNowChanged();
    }
}

int64_t UISessionModel::getTimeStamp()
{
  return  m_timestamp;
}


